package com.ruoyi.web.course;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.course.vo.TuCourseVo;
import com.ruoyi.course.service.ITuCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 助教课程Controller
 *
 * @author ruoyi
 * @date 2024-12-03
 */
@Api(tags = "助教课程Controller")
@RestController
@RequestMapping("/course/tu_course")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TuCourseController extends BaseController {

    private final ITuCourseService tuCourseService;

    @ApiOperation("查询助教课程列表")
    @PreAuthorize("@ss.hasPermi('course:tu_course:list')")
    @GetMapping("/list")
    public TableDataInfo<TuCourseVo> list(TuCourseVo entity) {
        return tuCourseService.queryList(entity);
    }

    @ApiOperation("查询助教课程所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(TuCourseVo entity) {
        return AjaxResult.success("查询成功", tuCourseService.queryAll(entity));
    }

    @ApiOperation("导出助教课程列表")
    @PreAuthorize("@ss.hasPermi('course:tu_course:export')")
    @Log(title = "助教课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TuCourseVo entity) {
        List<TuCourseVo> list = tuCourseService.queryAll(entity);
        ExcelUtil<TuCourseVo> util = new ExcelUtil<>(TuCourseVo.class);
        util.exportExcel(response, list, "助教课程数据");
    }

    @ApiOperation("获取助教课程详细信息")
    @PreAuthorize("@ss.hasPermi('course:tu_course:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", tuCourseService.queryById(id));
    }

    @ApiOperation("新增助教课程")
    @PreAuthorize("@ss.hasPermi('course:tu_course:add')")
    @Log(title = "助教课程", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody TuCourseVo entity) {
        return toAjax(tuCourseService.save(entity));
    }

    @ApiOperation("修改助教课程")
    @PreAuthorize("@ss.hasPermi('course:tu_course:edit')")
    @Log(title = "助教课程", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody TuCourseVo entity) {
        return toAjax(tuCourseService.updateById(entity));
    }

    @ApiOperation("删除助教课程")
    @PreAuthorize("@ss.hasPermi('course:tu_course:remove')")
    @Log(title = "助教课程", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tuCourseService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
